#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

#define THREAD_COUNT 2

int g_tickets = 100;



//黄牛（线程）要执行的代码
void* get_tickets_start(void* arg){
    pthread_detach(pthread_self());
    while(1){
        if(g_tickets > 0){
            //1.打印下-
            printf("i am %p, i get ticket %d\n", pthread_self(), g_tickets);
            //2.减减
            g_tickets--;
        }else{ // g_tickets <=0
            break;
        }
    }
    return NULL;
}


int main(){
  for(int i = 0; i < THREAD_COUNT; i++){
        pthread_t tid;
        int ret = pthread_create(&tid, NULL, get_tickets_start, NULL);
        if(ret < 0){
            return 0;
        }
    }
  while(1){
        sleep(1);
    }

  return 0;
}
